<?
require_once( '../../includes/init.php');
function checkLogin() 
	{
		require_once ('../class_passport.php' );
		$clsPassport = new x_Passport;
		$clsPassport->appId = 10; // 通行证服务ID
		$clsPassport->encryptKey = 'k4kfEOJdi9asUWKKSDXxCKDIfjsoUH5Aa09dnAB'; // 私钥
		/****** 登陆认证 ******/
		// 第一步：
		$clsPassport->verify ();

		// 第二步，保存 Passport 信息到当前程序的 Session
		$userSession = $clsPassport->vars;
		/*
		这里为保存 Session 代码
		*/
		if ( $clsPassport->vars['app_user_id'] > 0 )
		{
			// 若账号已激活表示已登陆当前程序
		}
		// 注：无需每次都验证 Passport，可以先通过用户在当前程序本身的 Session 判断是否已登陆
        //print_r($userSession);die();

		/****** 获取程序列表 ******/
		// $appType : 程序的类型, 系统程序为 1, 游戏为 2
		//$appList = $clsPassport->appGetList ( $appType );
		$_SESSION['union_username'] = $userSession["username"];
		$_SESSION['union_nickname'] = $userSession["nickname"];
		return $_SESSION['union_username'];
	}

if ($_SESSION['union_username'] =='' && $_POST['keyword']=='') {
    checkLogin();
}

$siteObj=alps::newClass('mod_site','mod');

$siteInfo = $siteObj->getSiteInfo($_SERVER['HTTP_HOST']);                                                     //得到站点信息
if (empty($siteInfo)) die('请检查域名是否错误');

require_once('../include.php');

$smarty->assign('siteInfo',$siteInfo);
if ($siteInfo['site_status']==3) {
echo "<script>alert('网站审核没有通过');window.close();</script>";die;
}
$tplInfo = $siteObj->getTpl($siteInfo['template_id']);                                                         //得到模板
$tplpath=$tplInfo['temppath'];

if ($_GET['sortid']) $sortid=intval($_GET['sortid']); 
elseif ($_GET['gsortid']) $gsortid=intval($_GET['gsortid']);

$smarty->cache_lifetime = 180;
$smarty->use_sub_dirs = true;
if ($_POST['keyword']!='') {
    $keyword=addslashes($_POST['keyword']);
} else {
    //$smarty->caching = true;
}

$my_cache_id=md5($_SERVER['HTTP_HOST']);
if(!$smarty->is_cached($tplpath.'news/news_list.html',$my_cache_id)) {
	$new_list = $siteObj->getsortlist($sortid,$gsortid,20,$keyword);                                               // 分类列表
	$smarty->assign('new_list',$new_list['result']);
	$smarty->assign('pagebar',$new_list['pagebar']);

	$new_news = $siteObj->getnewslist('','',10);                                                                   //最新资讯
	$articleInfo['content']=stripslashes($articleInfo['content']);
	$smarty->assign('new_news',$new_news);

	$sort_arr=$siteObj->get_sort_arr();
	foreach ($sort_arr as $sortinfo) {
		if ($sortid==$sortinfo['sortid']) {
			$smarty->assign('sortname',$sortinfo['sortname']);
		}
	}
	$gsort_arr=$siteObj->get_gsort_arr();
	foreach ($gsort_arr as $gsortinfo) {
		if ($gsortid==$gsortinfo['game_id']) {
			$smarty->assign('sortname',$gsortinfo['game_title']);
		}
	}
}
//print_r($new_list['result']);
$smarty->assign('backaddress',$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
$cachepath1=substr($my_cache_id,0,2);
$cachepath2=substr($my_cache_id,2,2);

$smarty->display($tplpath.'news/news_list.html',$cachepath1.'|'.$cachepath2.'|'.$my_cache_id.'|'.'sid'.$sortid.'gid'.$gsortid); 

?>